//
//  ZXUserDetailInfo.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/11.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "ZXUserDetailInfo.h"

@implementation ZXUserDetailInfo
-(void)setUserType:(NSString *)userType{
    _userType = userType;
    
    switch (userType.integerValue) {
        case 1:
            _usertypename = @"小农";
            break;
        case 2:
            _usertypename = @"农场员工";
            break;
        case 3:
            _usertypename = @"散户";
            break;
        case 4:
            _usertypename = @"决策者";
            break;
        case 5:
            _usertypename = @"联社业务代表";
            break;
        case 6:
            _usertypename = @"组织业务代表";
            break;
            
        default:
            _usertypename = @"小农";
            break;
    }
}
-(void)setPhoto:(NSString *)photo{
    _photo = photo;
    NSLog(@"%@",photo);
    NSString * urlString = [photo stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    [[ZXHTTPManager sharedManager] GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        UIImage * image = [UIImage imageWithData:responseObject];
        self.photoImage = image;
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"MyHeaderIconNotification" object:nil userInfo:nil];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
}
-(void)setAddress:(NSString *)address{
    _address = address;
    
    self.filteredAddress = address;
    
    NSLog(@"address = %@",address);
    
    NSArray<NSString *> * strings =  [address componentsSeparatedByString:@"|"];
    
    NSMutableString * strM = [NSMutableString string];
    for(int i = 0; i < strings.count; i++) {
        if (i == strings.count - 1) {
            //            NSLog(@"%@",[self foo:strings[i] needNumber:YES]);
            [strM appendString:[self foo:strings[i] needNumber:YES]];
        }else{
            
            //            NSLog(@"%@",[self foo:strings[i] needNumber:NO]);
            [strM appendString:[self foo:strings[i] needNumber:NO]];
        }
    }
    
    self.filteredAddress = strM;
}
- (NSString *)foo:(NSString *)str needNumber:(BOOL)needNumber
{
    NSMutableString * strM = [NSMutableString string];
    NSString *searchText = str;
    
    NSString * RegExString;
    if (needNumber) {
        
        RegExString = @"[\u4E00-\u9FFF\\d]+";
    }else{
        RegExString = @"[\u4E00-\u9FFF]+";
        
    }
    
    NSRange range = [searchText rangeOfString:RegExString options:NSRegularExpressionSearch];
    while (range.location != NSNotFound) {
        
        [strM appendString:[NSString stringWithFormat:@"%@ ",[searchText substringWithRange:range]]];
        searchText =  [searchText substringFromIndex:range.location+range.length];
        range = [searchText rangeOfString:RegExString options:NSRegularExpressionSearch];
    }
    //    NSLog(@"%@",strM);
    
    return strM;
    
    
    /*
     NSRange range = [searchText rangeOfString:@"[\u4E00-\u9FFF]+" options:NSRegularExpressionSearch];
     while (range.location != NSNotFound) {
     
     [strM appendString:[NSString stringWithFormat:@"%@ ",[searchText substringWithRange:range]]];
     searchText =  [searchText substringFromIndex:range.location+range.length];
     range = [searchText rangeOfString:@"[\u4E00-\u9FFF]+" options:NSRegularExpressionSearch];
     }
     
     //    NSLog(@"strM = %@",strM);
     
     return strM;
     */
}
//-(void)setADDRESS:(NSString *)ADDRESS{
//    _ADDRESS = ADDRESS;
//    NSLog(@"REGADDR = %@",ADDRESS);
//
//    NSArray<NSString *> * strings =  [ADDRESS componentsSeparatedByString:@"|"];
//
//    NSMutableString * strM = [NSMutableString string];
//    for(int i = 0; i < strings.count; i++) {
//        if (i == strings.count - 1) {
//            //            NSLog(@"%@",[self foo:strings[i] needNumber:YES]);
//            [strM appendString:[self foo:strings[i] needNumber:YES]];
//        }else{
//
//            //            NSLog(@"%@",[self foo:strings[i] needNumber:NO]);
//            [strM appendString:[self foo:strings[i] needNumber:NO]];
//        }
//    }
//
//    self.filteredAfterADDRESS = strM;
//}
//- (NSString *)foo:(NSString *)str needNumber:(BOOL)needNumber
//{
//    NSMutableString * strM = [NSMutableString string];
//    NSString *searchText = str;
//
//    NSString * RegExString;
//    if (needNumber) {
//
//        RegExString = @"[\u4E00-\u9FFF\\d]+";
//    }else{
//        RegExString = @"[\u4E00-\u9FFF]+";
//
//    }
//
//    NSRange range = [searchText rangeOfString:RegExString options:NSRegularExpressionSearch];
//    while (range.location != NSNotFound) {
//
//        [strM appendString:[NSString stringWithFormat:@"%@ ",[searchText substringWithRange:range]]];
//        searchText =  [searchText substringFromIndex:range.location+range.length];
//        range = [searchText rangeOfString:RegExString options:NSRegularExpressionSearch];
//    }
//    //    NSLog(@"%@",strM);
//
//    return strM;
//
//
//    /*
//     NSRange range = [searchText rangeOfString:@"[\u4E00-\u9FFF]+" options:NSRegularExpressionSearch];
//     while (range.location != NSNotFound) {
//
//     [strM appendString:[NSString stringWithFormat:@"%@ ",[searchText substringWithRange:range]]];
//     searchText =  [searchText substringFromIndex:range.location+range.length];
//     range = [searchText rangeOfString:@"[\u4E00-\u9FFF]+" options:NSRegularExpressionSearch];
//     }
//
//     //    NSLog(@"strM = %@",strM);
//
//     return strM;
//     */
//}
@end
